﻿using Iworld.Administrator.Model;
using Iworld.basis.Service;
using Iworld.Basis.Help;
using Iworld.Basis.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Administrator.Service.Import
{
    [DataContract]
    public class EditPasswordImport : CheckAdministratorImportBase, IPackageForUpdateModel<IModelToDbContextOfAdministrator,
         Iworld.Administrator.Model.Administrator>
    {

        public int Id
        {
            get { return this.Self.Id; }
        }

        /// <summary>
        /// 用户旧密码
        /// </summary>
        [DataMember]
        public string OldPassword { set; get; }

        /// <summary>
        /// 用户新密码
        /// </summary>
        [DataMember]
        public string NewPassword { set; get; }

        public void CheckData(IModelToDbContextOfAdministrator db)
        {
            this.OldPassword = EncryptHelper.EncryptByMd5(this.OldPassword);
            if (this.Self.Password != this.OldPassword)
            {
                throw new Exception("原密码不正确");
            }
            VerifyHelper.Check(this.NewPassword,Iworld.Basis.Help.VerifyHelper.Key.Password);
            this.NewPassword = EncryptHelper.EncryptByMd5(this.NewPassword);
        }

        public void Update(Model.Administrator model)
        {
            model.Password = this.NewPassword;
        }
    }
}
